package com.optional;

import java.util.Optional;

public class Optional类 {
	public static void main(String[] args) {
		Student s1 = new Student("test1",12);
		Optional<Student> o1 = Optional.of(s1);
		
		//判断对应的value是否为null
		System.out.println(o1.isEmpty());
		System.out.println(o1.isPresent());
		
		//如果value不为null，则可以通过get方法获取value
		System.out.println(o1.get());
	}
}

class Student{
	private String userName;
	private int userAge;
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public int getUserAge() {
		return userAge;
	}
	public void setUserAge(int userAge) {
		this.userAge = userAge;
	}
	public Student(String userName, int userAge) {
		this.userName = userName;
		this.userAge = userAge;
	}
}